<template>
    <div>
        地址名称:{{ info.name }}
        <p @click="selectAddress">地址数据:{{ info.address }}</p>
        <van-popup v-model="show" position="bottom">
            <van-area title="标题" :area-list="areaList" @confirm="getAddress" />
        </van-popup>
        <button @click="save">
            保存
        </button>
    </div>  
</template>

<script>
import {
    detailAction,
    saveAction
} from "@/api/cart/order/address/edit"
import { areaList } from '@vant/area-data';
export default {
    data() {
        return {
            info:{},
            areaList,
            show:false
        };
    },
    computed: {

    },
    created() {
        // 先判断当前执行的是编辑还是新增
        if(this.$route.params.id){ // 编辑
            detailAction({
                id:this.$route.params.id
            })
            .then(res =>{
                console.log(res)
                this.info = res.data
            })
        }
        
    },
    mounted() {

    },
    methods: {
        save(){
            saveAction({
                address:this.info.address,
                addressId:this.info.id,
                checked:false,
                detailadress:this.info.address_detail,
                openId:localStorage.getItem("openId"),
                telNumber:this.info.mobile,
                userName:this.info.name,
            })
            .then(res =>{
                console.log(res)
            })
        },
        getAddress(val){
            console.log(val)
            this.info.address = val.map(ele=>ele.name).join(" ")
            this.show = !this.show
        },
        selectAddress(){
            this.show = !this.show
        }
    },
};
</script>

<style scoped lang="scss">

</style>
